<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>上传图片--->详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <link rel="stylesheet" href="${ctxPath}/static/manage/layui/css/layui.css" media="all">
</head>
<body>
<form id="formUpdate" class="layui-form">
    <div class="layui-form-item">
        <label  class="layui-form-label">图片</label>
        <div class="layui-col-md3 layui-col-xs5">
            <div class="layui-upload-list thumbBox mag0 magt3">
                <img class="layui-upload-img thumbImg" src="${complaint.img}" style="width: 300px;height: 300px">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <button  class="layui-btn" type="button" lay-filter="update" lay-submit="">完成</button>
    </div>
    <input type="hidden" name="id" value="${complaint.id}" id="id">
    <input type="hidden" name="img" value="${complaint.img}" id="imgUrl">
</form>
</body>
<script src="${ctxPath}/static/manage/layui/layui.js" charset="utf-8"></script>
<script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
<script src="${ctxPath}/static/manage/js/jquery.js"></script>
<script>
    layui.use(["upload","layer","form"], function(){
        var upload = layui.upload;
        var form=layui.form;
        var layer=layui.layer;
        var $ = layui.$;
        //执行实例
        var uploadInst = upload.render({
            elem: '.thumbBox' //绑定元素
            ,url: '/kaptcha/uploadImgUpd',
            //accept: 'images', //只允许上传图片
            before: function(obj){
                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                layer.load();
                obj.preview(function(index, file, res){
                    $('.thumbImg').attr('src', res);
                });
            },
            done: function(res){
                //上传完毕回调
                if(res.code==0){
                    layer.closeAll('loading');
                    $("#imgUrl").val(res.data);
                    $('.thumbBox').css("background","#fff");
                }else{
                    alert(res.data);
                    return;
                }
            }
        });

        // 监听提交
        form.on('submit(update)', function(){
            var imgUrl = $("#imgUrl").val();
            if( imgUrl == ""){
                alert("请选择图片");
                return;
            }
            $.ajax({
                url:'/manage/complaints/complainUpdate',
                type:'post',
                data:$("#formUpdate").serialize(),
                dataType:'text',
                success :function(res){
                    alert(res);
                    window.parent.location.reload();
                }
            });
        });
    });




</script>
</html>